<template>
  <div class="login-container">
    <div class="login-form">
      <div class="login-header">系统登录</div>
      <el-form :model="form" ref="form" label-width="80px">
        <el-form-item label="用户名" :rules="[{ required: true, message: '请输入用户名', trigger: 'blur' }]">
          <el-input v-model="form.username" placeholder="请输入用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码" :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]">
          <el-input type="password" v-model="form.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    };
  },
  methods: {
    login() {
      if(this.form.username === '' || this.form.password === '') {
        this.$message.error('请输入用户名和密码');
        return;
      }
      else if(this.form.username === 'admin' || this.form.password === '123456') {
      this.$message.success('登录成功！');
      // 执行登录逻辑，跳转到主页
      this.$router.push('/home');
    }
    else {
      this.$message.error('用户名或密码错误');
    }
  }
  }
};
</script>

<style scoped>
.login-container {
  background: url('/src/assets/background.png') no-repeat center center fixed;
  background-size: cover;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-form {
  background-color: rgba(255, 255, 255, 0.8);
  padding: 40px;
  border-radius: 8px;
  width: 400px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.login-header {
  text-align: center;
  font-size: 24px;
  color: #409eff;
  margin-bottom: 20px;
}

.el-form-item {
  margin-bottom: 20px;
}

.el-button {
  width: 100%;
}
</style>